//获取用户信息
$(function() {
    $.ajax({
        type: 'get',
        url: BigNew.user_detail,
        success: function(res) {
            console.log(res);
            if (res.code == 200) {
                for (let key in res.data) {
                    $('.' + key).val(res.data[key])
                        // console.log($('.' + key));
                }
                $('.user_pic').attr('src', res.data.userPic)
            }
        }
    })

    //获取图片预览功能
    $('#exampleInputFile').on('change', function() {
        let pic = this.files[0];
        let picUrl = URL.createObjectURL(pic)
        $('.user_pic').attr('src', picUrl)
    });

    //通过点击按钮修改个人信息
    $('.btn-edit').click(function(e) {
        e.preventDefault();
        let fd = new FormData(document.querySelector('form'));
        $.ajax({
            type: 'post',
            url: BigNew.user_edit,
            data: fd,
            contentType: false,
            processData: false,
            success: function(res) {
                console.log(res);
                if (res.code == 200) {
                    alert(res.msg)
                        //重新加载页面，只有live server插件才起作用
                    parent.window.location.reload()
                }
            }
        })
    })
})